using CMS.api.Entity;
using Microsoft.EntityFrameworkCore;

namespace CMS.api.Data
{
    public class CMSDb : DbContext
    {
        public CMSDb(DbContextOptions options) :
            base(options)
        {


        }

        public DbSet<Users> Users { get; set; }

        public DbSet<Articles> Articles { get; set; }

        public DbSet<Article_Content> Article_Content { get; set; }

        public DbSet<Article_Like> Article_Like { get; set; }

        public DbSet<Article_Low> Article_Low { get; set; }

        public DbSet<Article_Picture> Article_Picture { get; set; }

        public DbSet<Article_View> Article_View { get; set; }

        public DbSet<Article_Comment> Article_Comment { get; set; }

        public DbSet<Article_Category> Article_Category { get; set; }

        public DbSet<Administrator> Administrator { get; set; }

        public DbSet<About> About { get; set; }

        public DbSet<AuditInfo> AuditInfo { get; set; }

        public DbSet<Security_ICP> Security_ICP { get; set; }

        public DbSet<Slideshow>  Slideshow { get; set; }

        // 配置数据库的连接(sql serve)
        // protected override void OnConfiguring(
        //     DbContextOptionsBuilder builder
        // ) =>
        //     builder.UseSqlServer(@"server=.;database=CMSDb;uid=sa;pwd=123456");

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // 初始化一个管理员用户 虽然Id是自动生成，但此处必须明确指定
            modelBuilder.Entity<Users>().HasData(
                new Users
                {
                    Id = 1,
                    Username = "hcj",
                    Password = "113",
                    IsAdmina = true,
                    IsActived = true,
                    IsDeleted = false,
                    CreatedTime = System.DateTime.Now,
                    UpdatedTime = System.DateTime.Now,
                    DisplayOrder = 0,
                    Remarks = ""
                }
            );
            modelBuilder.Entity<Administrator>().HasData(
                new Administrator
                {
                    Id = 1,
                    UserId=1,
                    IsActived = true,
                    IsDeleted = false,
                    CreatedTime = System.DateTime.Now,
                    UpdatedTime = System.DateTime.Now,
                    DisplayOrder = 0,
                    Remarks = ""
                }
            );
            modelBuilder.Entity<Article_Category>().HasData(
                new Article_Category
                {
                    Id = 1,
                    CategoryName = "Vue",
                    IsActived = true,
                    IsDeleted = false,
                    CreatedTime = System.DateTime.Now,
                    UpdatedTime = System.DateTime.Now,
                    DisplayOrder = 0,
                    Remarks = ""
                },
                 new Article_Category
                 {
                     Id = 2,
                     CategoryName = "Asp.Net",
                     IsActived = true,
                     IsDeleted = false,
                     CreatedTime = System.DateTime.Now,
                     UpdatedTime = System.DateTime.Now,
                     DisplayOrder = 0,
                     Remarks = ""
                 },
                 new Article_Category
                 {
                     Id = 3,
                     CategoryName = "JavaScript",
                     IsActived = true,
                     IsDeleted = false,
                     CreatedTime = System.DateTime.Now,
                     UpdatedTime = System.DateTime.Now,
                     DisplayOrder = 0,
                     Remarks = ""
                 },
                 new Article_Category
                 {
                     Id = 4,
                     CategoryName = "C#",
                     IsActived = true,
                     IsDeleted = false,
                     CreatedTime = System.DateTime.Now,
                     UpdatedTime = System.DateTime.Now,
                     DisplayOrder = 0,
                     Remarks = ""
                 }
            );
            modelBuilder.Entity<Security_ICP>().HasData(
               new Security_ICP
               {
                   Id = 1,
                   ICP = "闽ICP备2020021665号",
                   PubliceSecurity = "闽公网安备 35012202350223号",
                   IsActived = true,
                   IsDeleted = false,
                   CreatedTime = System.DateTime.Now,
                   UpdatedTime = System.DateTime.Now,
                   DisplayOrder = 0,
                   Remarks = ""
               }
           );
            base.OnModelCreating(modelBuilder);
        }
    }
}
